<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"  xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:replace="_header_include::frag(~{::title},~{::style},~{})">
    <title>后台管理系统</title>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="css/element-ui.css">
    <link rel="stylesheet" href="css/base.css">
    <style>
    .el-date-picker__time-header{display: none;}
    </style>
</head>
<body>
<div id="optimizeClueManagement" class="optimizeClueManagement mainPadding" style="display: none;">
    <el-breadcrumb separator="/" class="elBreadcrumb marginB20">
        <el-breadcrumb-item>Home</el-breadcrumb-item>
        <el-breadcrumb-item>充值管理</el-breadcrumb-item>
        <el-breadcrumb-item>{{userName}}消费记录</el-breadcrumb-item>
    </el-breadcrumb>
    <el-row class="marginB20">        
        <el-button type="warning" @click="exportFun">导出记录</el-button>
    </el-row>
    <div class="mainSearchBg">        
        <div class="mainSearchFormBox">
            <el-form :inline="true" class="demo-form-inline mainSearchForm" :model="form" ref="form"> 
                <!-- <el-form-item label="消费商家:" label-width="auto">
                    <el-select v-model="form.userId" filterable  clearable placeholder="商家账户名">
                        <el-option
                            v-for="item in merchantUserListOptions"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>                 -->
                <el-form-item label="消费日期:">
                    <el-date-picker
                        format="yyyy-MM-dd"  
                        value-format="yyyy-MM-dd"
                        v-model="form.createDateStart"
                        type="datetime"
                        placeholder="选择日期时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="—" class="widthauto">
                    <el-date-picker
                        format="yyyy-MM-dd"  
                        value-format="yyyy-MM-dd"
                        v-model="form.createDateEnd"
                        type="datetime"
                        placeholder="选择日期时间">
                    </el-date-picker>
                </el-form-item>                
                <el-form-item label="">
                    <el-button icon="el-icon-search" type="primary" @click="searchTable('form')"  class="searchBtn" style="margin-left: 10px;">搜索</el-button>
                </el-form-item>
            </el-form>
        </div>
        <el-row>            
            <el-table
                ref="multipleTable"
                tooltip-effect="dark"
                style="width: 100%"
                border
                :data="dataTable"
                @selection-change="handleSelectionChange"
            >
                <el-table-column align="center" type="selection" width="55"></el-table-column>
                <el-table-column align="center" type="index" label="序号"  width="55"></el-table-column>
                <!-- <el-table-column align="center" prop="userName" label="商家名称"></el-table-column> -->
                <el-table-column align="center" prop="createDate" label="消费日期"  :formatter="dateFormat"></el-table-column>                
                <el-table-column align="center" prop="amount" label="消费金额"></el-table-column>
                <el-table-column align="center" prop="clueNum" label="获取资源条数"></el-table-column>
            </el-table>
            <table-pagination :pager="pager" @change="searchTable"></table-pagination>
        </el-row>
    </div>
</div>
</body>
<!-- import Vue before Element -->
<div th:include="_footer_include :: #jsLib"></div>

<!-- import common js-->
<script th:inline="javascript">
    var merchantUserList=[[${userList}]];//商户集合
    var mainAccountId=[[${mainAccountId}]];//商户id
    var ocmVM = new Vue({
        el: '#optimizeClueManagement',
        data: function() {
            return {
                pendingReviewNum:'',
                multipleSelection: [],//选择行
                merchantUserListOptions:merchantUserList,
                pager:{
                  total: 0,
                  currentPage: 1,
                  pageSize: 20,
                },
                form: {
                  userId:'',
                  createDateStart:'',
                  createDateEnd:''
                },
                formLabelWidth: '120px',
                dataTable: [],
                userName:'',
            }        	  
        },
        methods: {
            clickRow(row){
                this.$refs.multipleTable.toggleRowSelection(row)
            },
            handleSelectionChange(val) {//选择节点的事件
                // console.log(val)
                this.multipleSelection = val;
            },
            handleStart(index, row) {
                console.log(index, row);
            },
            handleForbid(index, row) {
                console.log(index, row);
            },
            searchTable() {
            	var startTime=this.form.createDateStart;
                var endTime=this.form.createDateEnd;
                if(endTime && startTime>endTime){
                    this.$message({
                        message: '结束时间不允许选择早于开始时间',
                        type: 'warning'
                    });
                    return;
                }
                var param ={};
                param.pageSize = this.pager.pageSize;
                param.pageNum = this.pager.currentPage;  
                param.mainAccountId = mainAccountId; 
                param.userId = this.form.userId; 
                param.createDateStart = this.form.createDateStart; 
                param.createDateEnd = this.form.createDateEnd; 
                console.info(param);
                axios.post('/merchant/consumeRecord/countListMerchant', param)
                .then(function (response) {
                    console.log(response)
                    var result =  response.data;
                    if(result.code==0){
                        var table=result.data;
                        ocmVM.dataTable= table.data;
                        ocmVM.userName=table.data[0].userName
                        ocmVM.pager.total =  table.total;
                        ocmVM.pager.currentPage = table.currentPage;
                    }else{
                        ocmVM.$message.error(result.msg);
                    }                    
                })
                .catch(function (error) {
                     console.log(error);
                });
                
            },
          //日期数据格式化方法
            dateFormat( row, column, cellValue, index) {
              if (cellValue == undefined) {
                 return "";
              }
              return moment(cellValue).format("YYYY-MM-DD");
            },
            exportFun(){
                var rows = this.multipleSelection;
                if(rows.length <1){
                    this.$message({
                        message: '请选择导出的数据',
                        type: 'warning'
                    });
                    return;
                }
                var param = rows;
                console.log(param)
                axios.post('/merchant/consumeRecord/countListMerchantExport',param,{responseType:'blob'})
                .then(function (response) {
                    console.log(response)
                    var data =  response.data;
                    var fileName = response.headers.filename;
                    saveAs(data,decodeURI(fileName));
                })
                .catch(function (error) {
                    console.log(error);
                }).then(function(){
                    ocmVM.loading=false;
                });

            },
        },
        created(){
            var localVal=localStorage.getItem('allChangePageSize')?parseInt(localStorage.getItem('allChangePageSize')):'';
            if(localVal){this.pager.pageSize = localVal;}
            // console.info("create method");
            this.searchTable();
        },
        mounted(){
            document.getElementById('optimizeClueManagement').style.display = 'block';
        }
  })
</script>
</html>